package com.itheima.test03;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/*

服务器：收到消息后给出反馈
 */
public class ServerDemo {

    public static void main(String[] args) throws IOException {
        //创建服务端对象
        ServerSocket ss = new ServerSocket(8858);

        //建立连接
        Socket accept = ss.accept();
        //获取输入流
        InputStream is = accept.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        String s;
        while ((s=reader.readLine())!=null){
            System.out.println(s);
        }
        //给出反馈
        //获取输出流
        OutputStream os = accept.getOutputStream();
        //写数据

        //现有  字符    字节
        //输出 Writer   OutputStream
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os));
        writer.write("晚上好1");
        writer.flush();
        //释放资源
       accept.shutdownOutput();
       // writer.close();
        ss.close();
    }
}
